package com.yenlien.traceyun.usercenter.dao;


import com.yenlien.traceyun.usercenter.entity.CompanyCustomAppVersion;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-07-21
 * @description:
 **/
public interface CompanyCustomAppVersionDao extends BaseJpaDao<CompanyCustomAppVersion> {

    public void deleteByCompanyId(String companyId);

    CompanyCustomAppVersion findByAppIdAndCompanyId(String appId, String companyId);

    List<CompanyCustomAppVersion> findByCompanyIdAndAppId(String companyId, String appId);

    List<CompanyCustomAppVersion> findByCompanyId(String companyId);

    /**
     * 根据政企ID获取可创建的企业数    001是控制中心 即政企
     *
     * @param parentId
     * @return
     */
    @Query(value = "SELECT * FROM t_company_customapp_version WHERE company_id = ?1 AND app_id = '001'", nativeQuery = true)
    CompanyCustomAppVersion findByParentId(String parentId);


    @Query(value = "SELECT cav.max_print,cav.max_scan,cav.custom_app_id FROM t_custom_app_version cav INNER JOIN t_company_customapp_version cv ON cav.id = cv.custom_app_version_id WHERE company_id = ?1", nativeQuery = true)
    Map<String, Object> findByCompanyIdMaxScan(String companyId);
}
